#include "form1.h"
#include "ui_form1.h"

Form1::Form1(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form1)
{
    ui->setupUi(this);

    // 设置表格控件
    ui->tableWidget->setColumnCount(5); // 设置列数
    ui->tableWidget->setHorizontalHeaderLabels({"住户", "温度℃", "湿度%", "电路", "时间"}); // 设置表头
    ui->tableWidget->setColumnWidth(0, 70);
    ui->tableWidget->setColumnWidth(1, 90);
    ui->tableWidget->setColumnWidth(2, 90);
    ui->tableWidget->setColumnWidth(3, 80);
    ui->tableWidget->setColumnWidth(4, 120);


    // 禁用表格的编辑功能
       ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);

       // 设置点击单元格时高亮整行
           ui->tableWidget->setStyleSheet(
               "QTableWidget::item:selected {"
               "background-color: #00008B;" // 设置高亮颜色
               "}"
           );

     connect(ui->tableWidget, &QTableWidget::cellClicked, [this](int row, int column){
               ui->tableWidget->selectRow(row);
           });
}

Form1::~Form1()
{
    delete ui;
}
